package statics;

import gameconstruction.GameObject;

import java.util.Collection;

import model.ModelContext;
import model.ModelObject;
import moving.Projectile;
import controller.SystemContext;
import datacontainers.Location2D;

public class Target extends GameObject{
	//static target image stuff here
	private int hp = 3; //number of hits before this Target is destroyed
	
	public Target(Location2D start) {
		super(start);
	}

	@Override
	public void draw() {
		//draw a target
	}

	@Override
	public void doStep(ModelContext mc, SystemContext sc) {
		Collection<ModelObject> collisions = mc.getCollisions(this);
		if(collisions.size()>0){
			Projectile projectile = null;
			for(ModelObject mo:collisions){
				if(mo instanceof Projectile){
					projectile = (Projectile)mo;
					break;
				}
			}
			if(projectile!=null){
				hp--;
				mc.destroy(projectile);
				ensureHP(mc);
			}
		}
	}
	
	private void ensureHP(ModelContext mc){
		if(hp<=0)mc.destroy(this);
	}
}